package com.peanut.baby.mvp.bbs;

import android.content.Context;
import android.text.Html;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.peanut.baby.R;
import com.peanut.baby.model.BBSMoment;
import com.peanut.baby.mvp.bbs.detail.BBSMomentDetailActivity;
import com.peanut.baby.mvp.profile.ProfileActivity;
import com.peanut.baby.util.TimeUtil;
import com.peanut.devlibrary.imageloader.ImageLoader;
import com.peanut.devlibrary.util.StringUtil;
import com.peanut.devlibrary.widget.pullrecycle.BaseRecyclerAdapter;
import com.peanut.devlibrary.widget.pullrecycle.BaseViewHolder;

import java.util.List;

/**
 * Created by anonymouslystudio on 2017/7/28.
 */

public class BBSRecycleListAdapter extends BaseRecyclerAdapter<BBSMoment>{
    public BBSRecycleListAdapter(Context context, List<BBSMoment> data) {
        super(context, data);
    }

    @Override
    protected void convert(BaseViewHolder holder, final BBSMoment item) {
        ImageView avatar = holder.getView(R.id.moment_avatar);
        ImageView hasImage = holder.getView(R.id.moment_image_flag);
        TextView nick = holder.getView(R.id.moment_nick);
        TextView time = holder.getView(R.id.moment_time);
        TextView category = holder.getView(R.id.moment_category);
        TextView content = holder.getView(R.id.moment_content);
        TextView scanCount = holder.getView(R.id.moment_scan_count);
        TextView cmtCount = holder.getView(R.id.moment_comment_count);

        ImageLoader.getInstance().loadImageView(mContext,item.avatar,avatar);
        if(!StringUtil.isNullOrEmpty(item.title)){
            content.setText(item.title);
        }else{
            content.setText(Html.fromHtml(StringUtil.getSimpleText(item.content)));
        }

        nick.setText(item.nickname);
        time.setText(TimeUtil.getDisplayTimeMillis(item.updateTime));
        hasImage.setVisibility(StringUtil.isNullOrEmpty(item.imgUrl)? View.GONE : View.VISIBLE);
        category.setText(item.type);
        scanCount.setText(item.viewCount+"");
        cmtCount.setText(item.commentCount+"");

        holder.getView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                BBSMomentDetailActivity.start(mContext,item.id+"");
            }
        });

        avatar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ProfileActivity.start(mContext,item.userId+"");
            }
        });
    }

    @Override
    protected int getLayoutId() {
        return R.layout.layout_item_bbs_moment;
    }
}
